package com.example.demo2;

import org.apache.commons.lang.StringUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.example.demo2.common.exception.TripleDESException;
import com.example.demo2.common.util.CommonValueUtil;
import com.example.demo2.common.util.MessageUtil;
import com.example.demo2.common.util.TripleDESUtil;


@SpringBootApplication
public class Demo2Application {

	public static void main(String[] args) {
		SpringApplication.run(Demo2Application.class, args);

		sendDeal("D002","32435","04","10","0.01",null,null);
	}


	private final static String MESSAGE_3DES_KEY = "Chaohui@11Corp";
	public static byte[] message3DESKey;
	static {
		if (CommonValueUtil.INTERFACE_MESSAGE_CIPHER) {
			try {
				message3DESKey = TripleDESUtil.build3DesKey(MESSAGE_3DES_KEY);
			} catch (TripleDESException e) {
				e.printStackTrace();
			}
		}
	}

	public static void service_notify(HttpServletRequest request, HttpServletResponse response){
		try {
			byte[] message3DESKey = TripleDESUtil.build3DesKey("Chaohui@11Corp");
			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
			DocumentBuilder db = dbf.newDocumentBuilder();
			org.w3c.dom.Document doc = db.parse(request.getInputStream());
			String xmlHtml= getXmlString(doc);
			System.out.println("异步回调结果HTML:" + xmlHtml);
			String xmlText = TripleDESUtil.decrypt(xmlHtml, message3DESKey);// 数据解密
			System.out.println("异步回调结果TEXT:" + xmlText);
		}catch (Exception e){
			e.printStackTrace();
		}
	}

	protected static String getXmlString(org.w3c.dom.Document doc){
		TransformerFactory tf = TransformerFactory.newInstance();
		try {
			Transformer t = tf.newTransformer();
			t.setOutputProperty(OutputKeys.ENCODING,"UTF-8");//解决中文问题，试过用GBK不行
			t.setOutputProperty(OutputKeys.METHOD, "html");
			t.setOutputProperty(OutputKeys.VERSION, "4.0");
			t.setOutputProperty(OutputKeys.INDENT, "no");
			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			t.transform(new DOMSource(doc), new StreamResult(bos));
			return bos.toString();
		} catch (TransformerConfigurationException e) {
			e.printStackTrace();
		} catch (TransformerException e) {
			e.printStackTrace();
		}
		return "";
	}

	public static void test() {
		String appid = "ddf298c34c482080";//平台分配的appid
		String appkey = "a75f6276fa1dfd4c55ecd0869bbfb906";//平台分配的appkey
		String url = "http://dish.51zcm.cc/merchant/interface/external";//请求地址
		String notify = "http://ulcadmin.zoumang.com/ccb/refund/callback";//回调地址
		Element responseThirdHead = DocumentHelper.createElement("head");
		responseThirdHead.addElement("type").addText("D002");
		responseThirdHead.addElement("appid").addText(appid);
		responseThirdHead.addElement("version").addText("1");
//<serialNo>201811010951592541802CA8962574</serialNo>
//		<batchNo>000001</batchNo>
//		<traceNo>4770573239380001b19Q2</traceNo>
//		<refNo></refNo>
//		<cardNo>4770573239380001b19Q2</cardNo>
		Element responseThirdBody = DocumentHelper.createElement("body");
//		responseThirdBody.addElement("innerMerchantNo").addText("00000001");
		responseThirdBody.addElement("terminalNo").addText("1802CA896257");
		responseThirdBody.addElement("orderNo").addText("3004");
		responseThirdBody.addElement("payMode").addText("1");
		responseThirdBody.addElement("splitMode").addText("1");
		responseThirdBody.addElement("payAppChannel").addText("04");
		responseThirdBody.addElement("payTransType").addText("2");
		responseThirdBody.addElement("amount").addText("0.01");
		responseThirdBody.addElement("orgTraceNo").addText("4770573239380001b19Q2");
		responseThirdBody.addElement("orgSerialNo").addText("201811010951592541802CA8962574");
//		Element listElement = responseThirdBody.addElement("list");
//
//		Element itemElement = listElement.addElement("item");
//		itemElement.addElement("title").addText("羽绒服");
//		itemElement.addElement("code").addText("01");
//		itemElement.addElement("count").addText("2");
//		itemElement.addElement("attr").addText("男短款");
//
//		Element itemElement1 = listElement.addElement("item");
//		itemElement1.addElement("title").addText("休闲裤");
//		itemElement1.addElement("code").addText("02");
//		itemElement1.addElement("count").addText("2");
//		itemElement1.addElement("attr").addText("修身");
		//异步回调地址(通过回调地址将交易结果以http请求xml格式报文传输回去)
		//解析方式与响应返回结果一致
		responseThirdBody.addElement("notify_url").addText(notify);
//		String content = "<html><body><p><div align=\\\"center\\\" style=\\\"font-size:30px;\\\">盈普测试专用欢迎您</div><div align=\\\"center\\\" style=\\\"font-size:20px;\\\">(第一联)</div><hr style=\\\"height:2px;border:none;border-top:1px  solid#000000;\\\"><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">商户名称:<span style=\\\"float:right\\\">盈普测试专用</span></div><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">商户号:<span style=\\\"float:right\\\">059100000000091</span></div><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">终端号::<span style=\\\"float:right\\\">50504200</span></div><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">操作员号:<span style=\\\"float:right\\\">admin</span></div><hr style=\\\"height:2px;border:none;border-top:1px  solid#000000;\\\"><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">交易日期:<span style=\\\"float:right\\\">2016-11-21 14:54:44</span></div><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">交易类型<span style=\\\"float:right\\\">现金收银</span></div><hr style=\\\"height:2px;border:none;border-top:1px  solid#000000;\\\"><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">交易金额:<span style=\\\"float:right\\\">7.00</span></div><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">流水号:<span style=\\\"float:right\\\">20161121025444241505042004</span></div><hr style=\\\"height:2px;border:none;border-top:1px  solid#000000;\\\"><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">应收金额:<span style=\\\"float:right\\\">7.00</span></div><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">实收金额:<span style=\\\"float:right\\\">7.00</span></div><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">找零:<span style=\\\"float:right\\\">0.00</span></div><hr style=\\\"height:2px;border:none;border-top:1px  solid#000000;\\\"><div align=\\\"center\\\" style=\\\"font-size:20px;\\\">谢谢惠顾</div></p></body></html>";
//		String content = "&lt;![CDATA[&lt;div align=\"center\" style=\"font-size:30px;\"&gt;吉诺车屋支付测试&lt;/div&gt;]]&gt;";
//		String content = "[\\\"!fontSize M\\\",\\\"* text C 居中文本ABCabc\\\",\\\"* line\\\",\\\"* feedline 2\\\"]";
//		responseThirdBody.addElement("printContentMerch").addText(content);
//		responseThirdBody.addElement("printContentStub").addText(content);

		String responseStr = MessageUtil.providerOutXml(responseThirdHead, responseThirdBody,appkey);

//		String responseStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><head><type>D002</type><time>1507129124033</time><result><code>00</code><msg>操作成功</msg></result></head><body><terminalNo>85425316</terminalNo><orderNo>26120031383</orderNo><payAppChannel>12</payAppChannel><payTransType>1</payTransType><resCode>00</resCode><resDesc>交易成功</resDesc><amt>2668.0</amt><giveAmt>0.00</giveAmt><serialNo>20171004225727007854253164</serialNo><batchNo>000001</batchNo><traceNo>000801</traceNo><refNo></refNo><cardNo>621226*********1496</cardNo><date></date><time></time></body><sign>8449bb509f02632856466b6cd5fe6ec6</sign></root>";
		System.out.println(responseStr);
		try {
			responseStr = TripleDESUtil.encrypt(responseStr, message3DESKey);// 数据加密
		} catch (TripleDESException e) {
			responseStr = "";// 加密异常时，直接清除数据
		}
//		responseStr = "uWIYgMhqHx3MFe31B3YaOlKszAym6dLRca2i2tyhpf/vohAFW9IRL3FaSUxIyBcR4sDVsiLAbi0YYUHPSGDT4NJefH62cWrj3CYzk7vVwrXKUDowpXO5sTTrTbT0UVkxmT2TuvuzV4C3n2v/rfpPxMLqyQDQJhDVj+E+sa9IXczMlqtqfnqlwP3agB4slKbYNVcgB0srjDr+txJLDzKX7Ij8vnX6r4WpuTckmrGamAlAao96IrZEB5Kfjk9Ya4HGzC2dZwQ2B1n8TVAqvRSM2NmLdqUNA+7+hBmUT899PXx2Usjk8nXfWUVS43JYdldxRK6Vk9Txx0j0HZrs0913ce/UAh/MMHS+R6NEAnIwmoiNMsoPbJ5QU1nHrFCl3LqSZsYu2wB16eBs7qjv+Pmrt4u5KRmANvyHw/SdTGKbFKlDTfOvonbbbG9Gd5Ti4IbsNqvI/oaLx7QHvfZV/83cvcpUhEfIaavbl/yLbD1xzafuzb0eBqFLMuKwmS3D0pYCUGhmV71bnshBjVUeYM/NNtyz0F9dqq8PT9wHdVySAtjjycjwAy3hGzeGfUnp2FRKLT9tE1Ne5sKstHvYKtb+FV4nXgXD8NMP430TCEq8pqmjD4MTGsH1VOfx5imO0vNSQXKAV1+8TAzAmQNF8AOTkX0KJvA2vI8RJT++24xLuZl/+JT+auLrpYOKpRWKBQhn4yPHu92LigVhM9nYas3iOKU+3ScEWgNC9vkNSsboTnYMsqXguRdXRbqtMpRIxR+Z7SaNepafIEL7Cw5a6acZysZ1doWLrqDenJcLkfWF4a0QoANWwWts2M3wt981m44Pdr0iBn4bV1qkwErul9em8Q92WZLoNlzRYts59YGDZrwDbjdphJp9zAHAZKKO6RyLg32dX/MV6y5/Ud+H8i8TtLHqdoqwrpwbMYZ5vMgUoh01PWp2XNAAQIeS6qRiC/xujF0uZ2pVkkutwGHzBpqJdstOoK28gNs+3+L7F/ZZdfpIM/gl9eNNf8r5uKCU75NJksvj16btNLppghqm85ltxtATVo1SPTcriOfNWN16xeUjN1B5PtwJQ5WNPVkBtJN7sMOfDKvoyEA3QIxOS1Zb7/yjb215nL7qAf/CZj/7Bm6uhax2uFXuGVxIq4Cej79TFNY7wdyGCTjD3AGkFSavcg==";
		System.out.println(responseStr);
		CloseableHttpClient closeableHttpClient = HttpClientBuilder.create().build();
		HttpPost httpPost;
		try {
			httpPost = new HttpPost(new URI(url));
			httpPost.addHeader("Content-Type", "text/xml");
			httpPost.setEntity(new StringEntity(responseStr));
			CloseableHttpResponse httpRes = closeableHttpClient.execute(httpPost);
			HttpEntity res = httpRes.getEntity();
			String xmlText =  EntityUtils.toString(res,"UTF-8");
			System.out.println("上送交易异步回调结果:" + xmlText);
			xmlText = TripleDESUtil.decrypt(xmlText.trim(), message3DESKey);// 数据解密
			System.out.println("上送交易异步回调结果:" + xmlText);

			Document doc = DocumentHelper.parseText(xmlText);
			Element requestRoot = doc.getRootElement();
			Element requestHead = requestRoot.element("head");
			Element requestBody = requestRoot.element("body");
			Element requestSign = requestRoot.element("sign");
			if (null == requestHead || null == requestBody || null == requestSign) {
				System.out.println("没有报文信息或接口报文不规范");
			}else {
				String sign = requestRoot.elementTextTrim("sign");
				if (!MessageUtil.checkSign(xmlText, sign,appkey)) {// 数据验签
					System.out.println("数据校验错误");
				} else {
					System.out.println("数据校验通过");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送请求到POS
	 * @param type 请求类型;D002-交易推送;D003 - 交易查询;
	 * @param orderNo 自定义订单号;每个订单号只能发送一次请求
	 * @param payAppChannel 支付通道:03、支付宝；04、微信; //11、银行卡收单；18、优惠立减；19、银联二维码；20、扫码支付; 21、龙支付; 01、现金结算; 05、会员支付
	 * @param payTransType 交易类型: 1 消费;2 消费撤销; 10 二维码收款;
	 * @param amount 交易金额
	 * @param orgTraceNo 原交易凭证号(在消费撤销情况下不能为空,其他类型不需要此参数)
	 * @param orgSerialNo 原交易流水号(在消费撤销情况下不能为空,其他类型不需要此参数)
	 */
	public static Map<String,Object> sendDeal(String type, String orderNo, String payAppChannel, String payTransType, String amount, String orgTraceNo, String orgSerialNo) {
		Map<String,Object> map = new HashMap<>();
		if(StringUtils.isBlank(type)||StringUtils.isBlank(orderNo)||StringUtils.isBlank(payAppChannel)||StringUtils.isBlank(payTransType)||StringUtils.isBlank(amount)){
			map.put("success",false);
			map.put("error","参数错误");
			return map;
		}
		if("2".equals(payTransType) &&(StringUtils.isBlank(orgTraceNo) || StringUtils.isBlank(orgSerialNo))){
			map.put("success",false);
			map.put("error","参数错误:消费撤销类型的原交易凭证号和原交易流水号不能为空");
			return map;
		}
		String appid = "ddf298c34c482080";//平台分配的appid
		String appkey = "a75f6276fa1dfd4c55ecd0869bbfb906";//平台分配的appkey
		String url = "http://dish.51zcm.cc/merchant/interface/external";//请求地址
		String notify = "";//回调地址 //http://ulcadmin.zoumang.com/ccb/refund/callback
		Element responseThirdHead = DocumentHelper.createElement("head");
		responseThirdHead.addElement("type").addText(type);
		responseThirdHead.addElement("appid").addText(appid);
		responseThirdHead.addElement("version").addText("1");
		Element responseThirdBody = DocumentHelper.createElement("body");
//		responseThirdBody.addElement("innerMerchantNo").addText("00000001");
		responseThirdBody.addElement("terminalNo").addText("1802CA896257");
		responseThirdBody.addElement("orderNo").addText(orderNo);
		responseThirdBody.addElement("payMode").addText("1");
		responseThirdBody.addElement("splitMode").addText("1");
		responseThirdBody.addElement("payAppChannel").addText(payAppChannel);
		responseThirdBody.addElement("payTransType").addText(payTransType);
		responseThirdBody.addElement("amount").addText(amount);
		if(StringUtils.isNotBlank(orgTraceNo)) {
			responseThirdBody.addElement("orgTraceNo").addText(orgTraceNo);
		}
		if(StringUtils.isNotBlank(orgSerialNo)) {
			responseThirdBody.addElement("orgSerialNo").addText(orgSerialNo);
		}
//		Element listElement = responseThirdBody.addElement("list");
//
//		Element itemElement = listElement.addElement("item");
//		itemElement.addElement("title").addText("羽绒服");
//		itemElement.addElement("code").addText("01");
//		itemElement.addElement("count").addText("2");
//		itemElement.addElement("attr").addText("男短款");
//
//		Element itemElement1 = listElement.addElement("item");
//		itemElement1.addElement("title").addText("休闲裤");
//		itemElement1.addElement("code").addText("02");
//		itemElement1.addElement("count").addText("2");
//		itemElement1.addElement("attr").addText("修身");
		//异步回调地址(通过回调地址将交易结果以http请求xml格式报文传输回去)
		//解析方式与响应返回结果一致
		responseThirdBody.addElement("notify_url").addText(notify);
//		String content = "<html><body><p><div align=\\\"center\\\" style=\\\"font-size:30px;\\\">盈普测试专用欢迎您</div><div align=\\\"center\\\" style=\\\"font-size:20px;\\\">(第一联)</div><hr style=\\\"height:2px;border:none;border-top:1px  solid#000000;\\\"><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">商户名称:<span style=\\\"float:right\\\">盈普测试专用</span></div><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">商户号:<span style=\\\"float:right\\\">059100000000091</span></div><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">终端号::<span style=\\\"float:right\\\">50504200</span></div><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">操作员号:<span style=\\\"float:right\\\">admin</span></div><hr style=\\\"height:2px;border:none;border-top:1px  solid#000000;\\\"><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">交易日期:<span style=\\\"float:right\\\">2016-11-21 14:54:44</span></div><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">交易类型<span style=\\\"float:right\\\">现金收银</span></div><hr style=\\\"height:2px;border:none;border-top:1px  solid#000000;\\\"><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">交易金额:<span style=\\\"float:right\\\">7.00</span></div><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">流水号:<span style=\\\"float:right\\\">20161121025444241505042004</span></div><hr style=\\\"height:2px;border:none;border-top:1px  solid#000000;\\\"><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">应收金额:<span style=\\\"float:right\\\">7.00</span></div><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">实收金额:<span style=\\\"float:right\\\">7.00</span></div><div style=\\\"text-align:left;width:375px;font-size:20px;\\\">找零:<span style=\\\"float:right\\\">0.00</span></div><hr style=\\\"height:2px;border:none;border-top:1px  solid#000000;\\\"><div align=\\\"center\\\" style=\\\"font-size:20px;\\\">谢谢惠顾</div></p></body></html>";
//		String content = "&lt;![CDATA[&lt;div align=\"center\" style=\"font-size:30px;\"&gt;吉诺车屋支付测试&lt;/div&gt;]]&gt;";
//		String content = "[\\\"!fontSize M\\\",\\\"* text C 居中文本ABCabc\\\",\\\"* line\\\",\\\"* feedline 2\\\"]";
//		responseThirdBody.addElement("printContentMerch").addText(content);
//		responseThirdBody.addElement("printContentStub").addText(content);

		String responseStr = MessageUtil.providerOutXml(responseThirdHead, responseThirdBody,appkey);

//		String responseStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><head><type>D002</type><time>1507129124033</time><result><code>00</code><msg>操作成功</msg></result></head><body><terminalNo>85425316</terminalNo><orderNo>26120031383</orderNo><payAppChannel>12</payAppChannel><payTransType>1</payTransType><resCode>00</resCode><resDesc>交易成功</resDesc><amt>2668.0</amt><giveAmt>0.00</giveAmt><serialNo>20171004225727007854253164</serialNo><batchNo>000001</batchNo><traceNo>000801</traceNo><refNo></refNo><cardNo>621226*********1496</cardNo><date></date><time></time></body><sign>8449bb509f02632856466b6cd5fe6ec6</sign></root>";
		System.out.println(responseStr);
		try {
			responseStr = TripleDESUtil.encrypt(responseStr, message3DESKey);// 数据加密
		} catch (TripleDESException e) {
			responseStr = "";// 加密异常时，直接清除数据
		}
//		responseStr = "uWIYgMhqHx3MFe31B3YaOlKszAym6dLRca2i2tyhpf/vohAFW9IRL3FaSUxIyBcR4sDVsiLAbi0YYUHPSGDT4NJefH62cWrj3CYzk7vVwrXKUDowpXO5sTTrTbT0UVkxmT2TuvuzV4C3n2v/rfpPxMLqyQDQJhDVj+E+sa9IXczMlqtqfnqlwP3agB4slKbYNVcgB0srjDr+txJLDzKX7Ij8vnX6r4WpuTckmrGamAlAao96IrZEB5Kfjk9Ya4HGzC2dZwQ2B1n8TVAqvRSM2NmLdqUNA+7+hBmUT899PXx2Usjk8nXfWUVS43JYdldxRK6Vk9Txx0j0HZrs0913ce/UAh/MMHS+R6NEAnIwmoiNMsoPbJ5QU1nHrFCl3LqSZsYu2wB16eBs7qjv+Pmrt4u5KRmANvyHw/SdTGKbFKlDTfOvonbbbG9Gd5Ti4IbsNqvI/oaLx7QHvfZV/83cvcpUhEfIaavbl/yLbD1xzafuzb0eBqFLMuKwmS3D0pYCUGhmV71bnshBjVUeYM/NNtyz0F9dqq8PT9wHdVySAtjjycjwAy3hGzeGfUnp2FRKLT9tE1Ne5sKstHvYKtb+FV4nXgXD8NMP430TCEq8pqmjD4MTGsH1VOfx5imO0vNSQXKAV1+8TAzAmQNF8AOTkX0KJvA2vI8RJT++24xLuZl/+JT+auLrpYOKpRWKBQhn4yPHu92LigVhM9nYas3iOKU+3ScEWgNC9vkNSsboTnYMsqXguRdXRbqtMpRIxR+Z7SaNepafIEL7Cw5a6acZysZ1doWLrqDenJcLkfWF4a0QoANWwWts2M3wt981m44Pdr0iBn4bV1qkwErul9em8Q92WZLoNlzRYts59YGDZrwDbjdphJp9zAHAZKKO6RyLg32dX/MV6y5/Ud+H8i8TtLHqdoqwrpwbMYZ5vMgUoh01PWp2XNAAQIeS6qRiC/xujF0uZ2pVkkutwGHzBpqJdstOoK28gNs+3+L7F/ZZdfpIM/gl9eNNf8r5uKCU75NJksvj16btNLppghqm85ltxtATVo1SPTcriOfNWN16xeUjN1B5PtwJQ5WNPVkBtJN7sMOfDKvoyEA3QIxOS1Zb7/yjb215nL7qAf/CZj/7Bm6uhax2uFXuGVxIq4Cej79TFNY7wdyGCTjD3AGkFSavcg==";
		System.out.println(responseStr);
		CloseableHttpClient closeableHttpClient = HttpClientBuilder.create().build();
		HttpPost httpPost;
		try {
			httpPost = new HttpPost(new URI(url));
			httpPost.addHeader("Content-Type", "text/xml");
			httpPost.setEntity(new StringEntity(responseStr));
			CloseableHttpResponse httpRes = closeableHttpClient.execute(httpPost);
			HttpEntity res = httpRes.getEntity();
			String xmlText =  EntityUtils.toString(res,"UTF-8");
			System.out.println("上送交易异步回调结果:" + xmlText);
			xmlText = TripleDESUtil.decrypt(xmlText.trim(), message3DESKey);// 数据解密
			System.out.println("上送交易异步回调结果:" + xmlText);

			Document doc = DocumentHelper.parseText(xmlText);
			Element requestRoot = doc.getRootElement();
			Element requestHead = requestRoot.element("head");
			Element requestBody = requestRoot.element("body");
			Element requestSign = requestRoot.element("sign");
			if (null == requestHead || null == requestBody || null == requestSign) {
				System.out.println("没有报文信息或接口报文不规范");
				map.put("success",false);
				map.put("error","没有报文信息或接口报文不规范");
				return map;
			}else {
				String sign = requestRoot.elementTextTrim("sign");
				if (!MessageUtil.checkSign(xmlText, sign,appkey)) {// 数据验签
					System.out.println("数据校验错误");
					map.put("success",false);
					map.put("error","数据校验错误");
					return map;
				} else {
					System.out.println("数据校验通过");
					map.put("body",xmlText);
					map.put("success",true);
					return map;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("success",false);
			map.put("error","请求失败");
			return map;
		}
	}
}